package com.mz.ozy.activity.assets;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.mz.ozy.R;
import com.mz.ozy.base.BaseActivity;
import com.mz.ozy.bean.LockInfoBean;
import com.mz.ozy.mvp.presenter.PledgePresenter;
import com.mz.ozy.mvp.view.PledgeContract;
import com.mz.ozy.utils.ToastUtils;
import com.mz.ozy.widget.dialog.PayPopupWindow;

import org.json.JSONObject;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PledgeActivity extends BaseActivity<PledgeContract.View, PledgePresenter> implements PledgeContract.View {

    @BindView(R.id.tv_wallet_type)
    TextView mTvWalletType;
    @BindView(R.id.tv_wallet_num)
    TextView mTvWalletNum;
    @BindView(R.id.et_amount)
    EditText mEtAmount;

    private PayPopupWindow mPayPopupWindow;
    private String balance;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pledge);
        ButterKnife.bind(this);
        initTitle();
        tvTitle.setVisibility(View.GONE);
        tvCenterTitle.setText(getString(R.string.balance_pledge));
        balance = getIntent().getStringExtra("amt");
        mTvWalletNum.setText(balance);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @OnClick({R.id.tv_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_sure:
                showPaypwdPop();
                break;
        }
    }


    public void showPaypwdPop() {
        if (mPayPopupWindow == null) {
            mPayPopupWindow = new PayPopupWindow(this, new PayPopupWindow.OnClickListener() {
                @Override
                public void onConfirm(String str) {
                    final String amt = mEtAmount.getText().toString().trim();
                    mPresenter.confirmStore(PledgeActivity.this, amt, str);
                }
            });
        }
        mPayPopupWindow.setPwdEmpty();
        mPayPopupWindow.showAtLocation(titleBar, Gravity.BOTTOM, 0, 0);


    }

    @Override
    public void getStorageInfoSuccess(LockInfoBean bean) {
        final List<LockInfoBean.WalletListBean> listWallet = bean.getListWallet();
        if (listWallet != null && listWallet.size() > 0) {
            final LockInfoBean.WalletListBean walletListBean = listWallet.get(0);
            mTvWalletNum.setText(walletListBean.getBalance());
        }
    }

    @Override
    public void confirmStoreSuccess(JSONObject bean) {
        ToastUtils.showToast(getResources().getString(R.string.pledge_success));
        startActivity(new Intent(this, PledgeRecordActivity.class));
        finish();
    }
}
